package me.sdevil507.org.controller;

import lombok.extern.slf4j.Slf4j;
import me.sdevil507.biz.common.exceptions.RoleCodeExistedException;
import me.sdevil507.biz.common.exceptions.RoleNameExistedException;
import me.sdevil507.org.dto.*;
import me.sdevil507.org.mapper.OrgResourceMapper;
import me.sdevil507.org.mapper.OrgRoleMapper;
import me.sdevil507.org.mapper.OrgUserMapper;
import me.sdevil507.org.po.OrgRolePo;
import me.sdevil507.org.po.OrgUserPo;
import me.sdevil507.org.service.OrgRoleService;
import me.sdevil507.supports.jpa.PageConvertCallBack;
import me.sdevil507.supports.jpa.PageResultDTO;
import me.sdevil507.supports.jpa.PageResultGenerator;
import me.sdevil507.supports.result.ApiResultDTO;
import me.sdevil507.supports.result.ApiResultGenerator;
import me.sdevil507.supports.shiro.realm.OrgUsernamePasswordRealm;
import me.sdevil507.supports.status.ApiStatusCode;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/api/expert/role")
@Slf4j
public class ExpertRoleController {


    @Autowired
    private OrgUsernamePasswordRealm orgUsernamePasswordRealm;

    /**
     * 获取权限字符串
     *
     * @return 权限字符串集合
     */
    @RequestMapping(value = "/findExpertPermissions", method = RequestMethod.POST)
    @ResponseBody
    public ApiResultDTO findExpertPermissions() {
        AuthorizationInfo authorizationInfo = orgUsernamePasswordRealm.doGetAuthorizationInfo(SecurityUtils.getSubject().getPrincipals());
        return ApiResultGenerator.create(ApiStatusCode.SUCCESS.getCode(), ApiStatusCode.SUCCESS.getDescription(), authorizationInfo.getStringPermissions());
    }
}